package app.mybatis;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
public class CityXmlDao {

  private final SqlSession sqlSession;

  public CityXmlDao(SqlSession sqlSession) {
    this.sqlSession = sqlSession;
  }

  public void add(City city) {
    sqlSession.insert("insertCity",city);
  }

  public City selectCityById(long id) {
    return sqlSession.selectOne("selectCityById", id);
  }

  @Transactional(rollbackFor=Throwable.class)
  public void addTransaction(City city1) {
    sqlSession.insert("insertCity",city1);
    int i= 1/0;
  }

//  public void addWithoutTransaction(City city1) {
//    sqlSession.insert("insertCity",city1);
//    int i= 1/0;
//  }
}